﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Common.CodeCommon;
using Microsoft.Office.Interop.Excel;

namespace Common.CodeCommon
{
    public class Opens
    {
        public void SaveExcelFile(DataGridView dgv)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "Excel Documents (*.xls)|*.xls";
            sfd.ValidateNames = true;
            string filelocation;
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                //ToCsV(dataGridView1, @"c:\export.xls");
                new Exports().ToCsV(dgv, sfd.FileName);
                filelocation = sfd.FileName;
            }
            if (MessageBox.Show("Lưu file hoàn tất. Bạn có muốn mở file?", "Lưu file hoàn tất", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
            {
                Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
                Workbook wb = excel.Workbooks.Open(sfd.FileName);
            }
        }
    }
}
